package com.leandom.studydemo.contentresolver;

import android.database.AbstractCursor;

import java.util.ArrayList;
import java.util.List;

public class MyCursor extends AbstractCursor {

    private List<List<Object>> rows = new ArrayList<>();
    private String[] columnNames;

    public MyCursor(List<List<Object>> rows, String[] columnNames) {
        this.rows = rows;
        this.columnNames = columnNames;
    }

    @Override
    public int getCount() {
        return rows != null ? rows.size() : 0;
    }

    @Override
    public String[] getColumnNames() {
        return columnNames;
    }

    @Override
    public String getString(int column) {
        return getColumn(column).toString();
    }

    @Override
    public short getShort(int column) {
        return Short.parseShort(getColumn(column).toString());
    }

    @Override
    public int getInt(int column) {
        return Integer.parseInt(getColumn(column).toString());
    }

    @Override
    public long getLong(int column) {
        return 0;
    }

    @Override
    public float getFloat(int column) {
        return 0;
    }

    @Override
    public double getDouble(int column) {
        return 0;
    }

    public Object getColumn(int column) {
        return rows.get(getPosition()).get(column);
    }

    @Override
    public boolean isNull(int column) {
        return false;
    }
}
